﻿using Microsoft.Extensions.Logging;
using Orleans;
using Orleans.Hosting;
using Orleans.Runtime.Configuration;
using Orleans.Runtime.Host;
using System;
using System.Threading.Tasks;
using Zj.OrleansDemo.Interface;
using Zj.OrleansDemo.Service;

namespace Zj.OrleansDemo.Server
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var host = RunAsync(22222,10086).Result)
            {
                Console.WriteLine("Press Any Key To ShutDown:");
                Console.ReadLine();

                host.StopAsync();
            }
        }

        private static async Task<ISiloHost> RunAsync(int siloPort=22222,int gatewayPort=40000)
        {
            var cfg = ClusterConfiguration.LocalhostPrimarySilo(siloPort, gatewayPort);

            var host = new SiloHostBuilder()
                .UseConfiguration(cfg)
                .ConfigureLogging(logging => logging.AddConsole())
                .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory().WithReferences())
                .Build();
            await host.StartAsync();
            return host;
        }
    }
}
